package repository

import (
	"gitee.com/ling1314/origin-utility/db"
	"gitee.com/ling1314/origin-utility/model"
)

type idpOrgRepository struct{}

func (r idpOrgRepository) FindOrg(userId int64) (li []model.IdpOrg, err error) {
	err = db.GetDB().Where("id in (select idp_org_id from idp_map_org_user where user_id = ?)", userId).
		Find(&li).Error
	return
}

func (r idpOrgRepository) FindOrgById(id int64) (m model.IdpOrg, err error) {
	err = db.GetDB().Where("id = ?", id).Find(&m).Error
	return
}

func (r idpOrgRepository) Update(m *model.IdpOrg) (err error) {
	err = db.GetDB().Save(m).Error
	return err
}

func (r idpOrgRepository) SaveOrgPoint(m *model.IdpOrgPoint) (err error) {
	err = db.GetDB().Save(m).Error
	return err
}

func (r idpOrgRepository) FindOrgPoint(planePicId string) (m model.IdpOrgPoint, err error) {
	err = db.GetDB().Where("plane_pic = ?", planePicId).Find(&m).Error
	return
}
